home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-07-28 | 9.5 KB | 589 lines | [TEXT/MPS ] |
- /*
- File: IncomingHFSStream.cp
-
- Contains:
-
- Written by: David Akhond
-
- Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
-
- To Do:
-
- */
-
-
- #ifndef __IncomingHFSStream__
- #include "IncomingHFSStream.h"
- #endif
-
-
-
- #pragma segment HFSSlot
-
- //---------------------
- // constructor
- //---------------------
-
- CIncomingHFSStream::CIncomingHFSStream(CFile* theLetterFile)
- {
-
- fLetterFile = theLetterFile;
-
- fLetterPos = eNone;
- fStreamPos = 0;
- fLineBufLen = 0;
- fLineBufPos = 0;
-
- OSErr err = fLetterFile->Open(fsRdWrPerm);
-
- }
-
-
-
- //-------------------
- // destructor
- //-------------------
-
- CIncomingHFSStream::~CIncomingHFSStream()
- {
-
- OSErr err = fLetterFile->Close();
-
- }
-
-
-
-
- //----------------------
- // Recipients
- //----------------------
-
- void CIncomingHFSStream::FromRecipient(char* author)
- {
- long newPosition = 0;
-
- fStreamPos = newPosition;
-
-
- fLetterFile->SetPosition( fStreamPos );
-
- this->FromField();
-
- strcpy(author, fFromRecipient);
-
- return;
- }
-
-
- //----------------------------------------
- Boolean CIncomingHFSStream::NextToRecipient(char* nextToRecipient)
- {
- long dataLen = 63;
- char commaSep = ',';
- char carReturn = 0x0D;
- char tempChar = 0x00;
- long tempRecipOffset = 0;
- Boolean more = true;
- Boolean toRecipComplete = false;
-
- memset(nextToRecipient, 0, 64);
-
- if (fLetterPos != eToRecips)
- {
- this->ToField();
- }
-
- if(fLetterPos == eToRecips)
- {
- while( !toRecipComplete )
- {
- if( tempRecipOffset > 62 )
- {
- toRecipComplete = true;
- }
- else
- {
- tempChar = fLineBuf[fLineBufPos];
- fLineBufPos++;
-
- if( (tempChar == ',') || (tempChar == 0x0D) )
- {
- toRecipComplete = true;
- nextToRecipient[tempRecipOffset] = 0x00;
- }
- else
- {
- nextToRecipient[tempRecipOffset] = tempChar;
- tempRecipOffset++;
- }
-
- if( tempChar == 0x0D )
- {
- more = false;
- }
- }
- }
- }
- else
- {
- more = false;
- }
-
- return(more);
- }
-
-
- //----------------------------------------
- Boolean CIncomingHFSStream::NextCCRecipient(char* nextCCRecipient)
- {
- long dataLen = 63;
- char commaSep = ',';
- char carReturn = 0x0D;
- char tempChar = 0x00;
- long tempRecipOffset = 0;
- Boolean more = true;
- Boolean ccRecipComplete = false;
-
- memset(nextCCRecipient, 0, 64);
-
- if (fLetterPos != eCCRecips)
- {
- this->CCField();
- }
-
- if(fLetterPos == eCCRecips)
- {
- while( !ccRecipComplete )
- {
- if( tempRecipOffset > 62 )
- {
- ccRecipComplete = true;
- }
- else
- {
- tempChar = fLineBuf[fLineBufPos];
- fLineBufPos++;
-
- if( (tempChar == ',') || (tempChar == 0x0D) )
- {
- ccRecipComplete = true;
- nextCCRecipient[tempRecipOffset] = 0x00;
- }
- else
- {
- nextCCRecipient[tempRecipOffset] = tempChar;
- tempRecipOffset++;
- }
-
- if( tempChar == 0x0D )
- {
- more = false;
- }
- }
- }
- }
- else
- {
- more = false;
- }
-
- return(more);
- }
-
-
-
- //----------------------------------------
- Boolean CIncomingHFSStream::NextBCCRecipient(char* nextBCCRecipient)
- {
- long dataLen = 63;
- char commaSep = ',';
- char carReturn = 0x0D;
- char tempChar = 0x00;
- long tempRecipOffset = 0;
- Boolean more = true;
- Boolean bccRecipComplete = false;
-
- memset(nextBCCRecipient, 0, 64);
-
- if (fLetterPos != eBccRecips)
- {
- this->BCCField();
- }
-
- if(fLetterPos == eBccRecips)
- {
- while( !bccRecipComplete )
- {
- if( tempRecipOffset > 62 )
- {
- bccRecipComplete = true;
- }
- else
- {
- tempChar = fLineBuf[fLineBufPos];
- fLineBufPos++;
-
- if( (tempChar == ',') || (tempChar == 0x0D) )
- {
- bccRecipComplete = true;
- nextBCCRecipient[tempRecipOffset] = 0x00;
- }
- else
- {
- nextBCCRecipient[tempRecipOffset] = tempChar;
- tempRecipOffset++;
- }
-
- if( tempChar == 0x0D )
- {
- more = false;
- }
- }
- }
- }
- else
- {
- more = false;
- }
-
- return(more);
- }
-
-
-
-
- //------------------------------------------
- Boolean CIncomingHFSStream::BodyText( char* textBuff, long* count )
- {
- long maxSize = *count;
- long amountRead = 0;
- char tempChar = 0x00;
- Boolean more = true;
- long lenFileRemaining;
- long filePosCurr;
- long fileSizeCurr;
-
- if (fLetterPos != eBody)
- {
- this->BodyField();
- }
-
- if(fLetterPos == eBody)
- {
-
- fileSizeCurr = fLetterFile->GetSize();
- filePosCurr = fLetterFile->GetPosition();
- lenFileRemaining = fileSizeCurr - filePosCurr;
-
- if( lenFileRemaining <= maxSize )
- {
- more = false;
- maxSize = lenFileRemaining;
- }
-
-
- for( long x = 0; x < maxSize; x++)
- {
-
- *(textBuff+x) = fLetterFile->ReadByte();
- amountRead++;
- fStreamPos++;
- fLetterFile->SetPosition(fStreamPos);
- }
-
- *count = amountRead;
-
- }
- else
- {
- *count = 0;
- more = false;
- }
-
- return(more);
- }
-
-
-
-
- //----------------------------
- // FromField
- //----------------------------
-
- void CIncomingHFSStream::FromField()
- {
- long charCount = 0;
- char lineBuf[kMaxLineLen];
- long maxSize = kMaxLineLen;
- char lineTerminator = 0x0D;
- Boolean fromFound = false;
- short fromRecipPos = 0;
-
- fLetterPos = eNone;
- memset(fFromRecipient, 0, 64);
- fStreamPos = 0;
- fLetterFile->SetPosition(fStreamPos);
-
- long eofMark = fLetterFile->GetSize();
-
- while( !fromFound )
- {
-
- charCount = fLetterFile->ReadLine (lineBuf,maxSize, lineTerminator);
-
- fStreamPos += charCount;
-
- fLetterFile->SetPosition(fStreamPos);
-
- if(charCount > 5)
- {
- if( (lineBuf[0] == 'F') && (lineBuf[1] == 'r') && (lineBuf[2] == 'o') && (lineBuf[3] == 'm') && (lineBuf[4] == ':') )
- {
- // we are on the 'From:' line
-
- if((charCount-5) > 1)
- {
- long x = 5;
-
- while( x < charCount )
- {
- char tempChar = *(lineBuf + x);
-
- if(tempChar == 0x0D)
- {
- break;
- }
- else
- {
- fFromRecipient[fromRecipPos] = tempChar;
- fromRecipPos++;
- }
-
- x++;
- }
- fFromRecipient[fromRecipPos] = 0x00;
- fromFound = true;
- fLetterPos = eFromRecips;
- }
- else
- {
- // set a default From recipient since there was no data
- strcpy (fFromRecipient, "defaultFrom");
- }
- }
- }
-
- if(fStreamPos == eofMark)
- {
- // if we're at the end of the file, then use the default From address
- strcpy (fFromRecipient, "defaultFrom");
- fromFound = true;
- }
-
- }
-
- }
-
-
-
-
- //----------------------------
- // ToField
- //----------------------------
-
- void CIncomingHFSStream::ToField()
- {
- long charCount = 0;
- Boolean toFound = false;
- char lineBuf[kMaxLineLen];
- long maxSize = kMaxLineLen;
- char lineTerminator = 0x0D;
-
- fLetterPos = eNone;
- fStreamPos = 0;
- fLetterFile->SetPosition(fStreamPos);
- long eofMark = fLetterFile->GetSize();
-
- while( !toFound )
- {
-
- charCount = fLetterFile->ReadLine(fLineBuf,maxSize, lineTerminator);
- fLineBufLen = charCount;
-
-
- fStreamPos += charCount;
-
- fLetterFile->SetPosition(fStreamPos);
-
- if( (fLineBuf[0] == 'T') && (fLineBuf[1] == 'o') && (fLineBuf[2] == ':') )
- {
- long x=3;
- fLineBufPos = x;
- fLetterPos = eToRecips;
- toFound = true;
- }
-
- if( fStreamPos == eofMark )
- {
- break;
- }
-
- }
-
-
- }
-
-
- //----------------------------
- // CCField
- //----------------------------
-
- void CIncomingHFSStream::CCField()
- {
- long charCount = 0;
- Boolean ccFound = false;
- char lineBuf[kMaxLineLen];
- long maxSize = kMaxLineLen;
- char lineTerminator = 0x0D;
- char currChar = 0x00;
-
- fLetterPos = eNone;
- fStreamPos = 0;
- fLetterFile->SetPosition(fStreamPos);
- long eofMark = fLetterFile->GetSize();
-
- while( !ccFound )
- {
-
- charCount = fLetterFile->ReadLine(fLineBuf,maxSize, lineTerminator);
- fLineBufLen = charCount;
-
-
- fStreamPos += charCount;
-
- fLetterFile->SetPosition(fStreamPos);
-
- if( (fLineBuf[0] == 'C') && (fLineBuf[1] == 'C') && (fLineBuf[2] == ':') )
- {
- long x=3;
- fLineBufPos = x;
- fLetterPos = eCCRecips;
- ccFound = true;
- }
-
- if( fStreamPos == eofMark )
- {
- break;
- }
-
- }
-
-
- }
-
-
-
- //----------------------------
- // BCCField
- //----------------------------
-
- void CIncomingHFSStream::BCCField()
- {
- long charCount = 0;
- Boolean bccFound = false;
- char lineBuf[kMaxLineLen];
- long maxSize = kMaxLineLen;
- char lineTerminator = 0x0D;
- char currChar = 0x00;
-
- fLetterPos = eNone;
- fStreamPos = 0;
- fLetterFile->SetPosition(fStreamPos);
- long eofMark = fLetterFile->GetSize();
-
- while( !bccFound )
- {
-
- charCount = fLetterFile->ReadLine(fLineBuf,maxSize, lineTerminator);
- fLineBufLen = charCount;
-
-
- fStreamPos += charCount;
-
- fLetterFile->SetPosition(fStreamPos);
-
- if( (fLineBuf[0] == 'B') && (fLineBuf[1] == 'C') && (fLineBuf[2] == 'C') && (fLineBuf[3] == ':') )
- {
- long x=4;
- fLineBufPos = x;
- fLetterPos = eBccRecips;
- bccFound = true;
- }
-
- if( fStreamPos == eofMark )
- {
- break;
- }
-
- }
-
-
- }
-
-
-
- //----------------------------
- // BodyField
- //----------------------------
-
- void CIncomingHFSStream::BodyField()
- {
- long charCount = 0;
- Boolean bodyFound = false;
- char lineBuf[kMaxLineLen];
- long maxSize = kMaxLineLen;
- char lineTerminator = 0x0D;
- char currChar = 0x00;
-
- fLetterPos = eNone;
- fStreamPos = 0;
- fLetterFile->SetPosition(fStreamPos);
- long eofMark = fLetterFile->GetSize();
-
- while( !bodyFound )
- {
-
- charCount = fLetterFile->ReadLine(fLineBuf,maxSize, lineTerminator);
- fLineBufLen = charCount;
-
-
- fStreamPos += charCount;
-
- fLetterFile->SetPosition(fStreamPos);
-
- if( (fLineBuf[0] == 'B') && (fLineBuf[1] == 'o') && (fLineBuf[2] == 'd') && (fLineBuf[3] == 'y') && (fLineBuf[4] == ':') )
- {
- long x=5;
- fLineBufPos = x;
- fLetterPos = eBody;
- bodyFound = true;
- }
-
- if( fStreamPos == eofMark )
- {
- break;
- }
-
- }
-
-
- }
-
-
-
-
-
-